
package com.koron.css2.workflow;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.PubReceiptBean;
import com.koron.css2.baseConfig.mapper.PubReceiptMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.Map;

/**
 *  显示流程审批界面html
 * 1、支持显示新建工作流界面，参数processinst为空，新建工作流界面与审批界面的区别是，新建界面只有通过选项，没有驳回、沟通等。
 * 2、支持显示审批界面，此功能与1.1.2功能一致
 * 3、支持显示详情界面，参数taskid为空，此界面仅显示流程历史记录，流程图，不显示流程办理功能区没有提交按扭等。
 * @author admin
 *
 */
public class ProcessShowView implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		
		MessageBean<String> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", String.class);
		try {
			// 1. 请求参数转map
			Map<String, String> map = JsonUtils.objectToPojo(req.getData(), Map.class);
			// 2. 工作流模板类别编号判空
			String billType = map.get("receiptType");
			if(StringUtils.isEmpty(billType)) {
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "receiptType 参数不能为空", Void.class);
			}
			String processInstanceId = map.get("processInstanceId");
			String taskId = map.get("taskId");
			String billId = map.get("billId");
			String staffcode = userInfo.getUserInfo().getCode();
			// 3. 通过工作流模板编号查询实例对象
			PubReceiptMapper pubMapper = factory.getMapper(PubReceiptMapper.class);
			String setCode = pubMapper.getWorkflowApp(userInfo.getCurWaterCode());
			PubReceiptBean receipt = pubMapper.selectPubReceipt(billType);
			// 4. 对实例进行判空
			if(receipt == null) {
				info.setCode(Constant.MESSAGE_INT_FAIL);
				info.setDescription("未获取到单据信息");
				return info;
			}
			String data = WorkflowImpl.workflowShowView(setCode, receipt.getProcessCode(), staffcode, taskId, processInstanceId, billId);
			info.setData(data);
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription(e.getMessage());
			logger.error(e.getMessage(), e);
		}
		return info;
	}

}
